<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>参试日志</title>
    <link href="/apps/css/bootstrap.min.css" rel="stylesheet">
    <link href="/apps/css/fontawesome-free-6.4.0-web/css/all.css" rel="stylesheet">
</head>
<body>
    <div class="container py-4">
        <div class="row mb-4">
            <div class="col">
                <h2>
                    <a href="/apps/trial" class="text-decoration-none">临床研究支持</a>
                    <i class="fas fa-chevron-right mx-2"></i>
                    {{#if isAdmin}}
                    <a href="/apps/trial/admin/trials/{{trial.id}}/subjects" class="text-decoration-none">受试者管理</a>
                    {{else}}
                    <a href="/apps/trial/track/{{trial.trial_code}}" class="text-decoration-none">在组试验</a>
                    {{/if}}
                    <i class="fas fa-chevron-right mx-2"></i>
                    参试日志
                </h2>
            </div>
            <div class="col-auto">
                <button type="button" class="btn btn-primary" onclick="createDiary()">
                    <i class="fas fa-plus me-1"></i>创建日记
                </button>
            </div>
        </div>

        <div class="row">
            {{#each diaries}}
            <div class="col-md-6 mb-4">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">{{formatDate diary_date "YYYY-MM-DD"}} T{{trial_id}}S{{subject_id}}</h5>
                        <p class="card-text">
                            <strong>早餐服用：</strong>{{content.morning_dose}} {{content.morning_missed_reason}} {{content.morning_missed_other}}
                            <strong>晚餐服用：</strong>{{content.evening_dose}} {{content.morning_missed_reason}} {{content.morning_missed_other}}
                            <strong>不良反应：</strong>{{content.side_effects}} {{content.side_effects_other}}
                            <strong>训练时长：</strong>{{content.training_duration}}
                            <br>
                            <strong>进展情况：</strong>{{content.progress}} {{created_at}}
                        </p>
                    </div>
                    <div class="card-footer">
                        <a href="/apps/trial/diary/{{id}}" class="btn btn-primary btn-sm">
                            <i class="fas fa-eye me-1"></i>查看
                        </a>
                        {{#if (within24H created_at)}}
                        <button type="button" class="btn btn-secondary btn-sm" onclick="editDiary({{id}})">
                            <i class="fas fa-edit me-1"></i>编辑
                        </button>
                        {{/if}}
                    </div>
                </div>
            </div>
            {{/each}}
        </div>
    </div>

    <script>
        function createDiary() {
            window.location.href = 'https://totemlife.cn/apps/trial/diary/create/{{trial.id}}';
        }

        function editDiary(id) {
            window.location.href = `https://totemlife.cn/apps/trial/diary/${id}/edit`;
        }
    </script>
</body>
</html> 
